package com.company.test23;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;

/**
 * Created by Administrator on 2016.9.29.
 */
public class Test2302 {
    public static void main(String[] args) {
        System.out.println("Enter a string:");
        Scanner input=new Scanner(System.in);

        String string=input.next();

        ArrayList<String> subsequence=new ArrayList<>();
        ArrayList<Character> ch=new ArrayList<>();

        for(int i=0;i<string.length();i++){
            int z=0;
            for(int j=0;j<subsequence.size();j++) {
                if (ch.get(j) <= string.charAt(i)) {
                    z=1;
                    for (int k = j; k < subsequence.size(); k++) {
                        subsequence.set(k, subsequence.get(k) + string.charAt(i));
                        ch.set(k, string.charAt(i));
                    }
                    break;
                }
            }
            if(z==0) {
                subsequence.add(string.charAt(i) + "");
                ch.add(string.charAt(i));
            }
        }

        int max=0;
        String maxSubsequence="";
        for (int i=0;i<subsequence.size();i++){
            if(subsequence.get(i).length()>max){
                max=subsequence.get(i).length();
                maxSubsequence=subsequence.get(i);
            }
        }

        System.out.println(maxSubsequence);
    }
}